/**
 * axios封装
 */
import store from '@/store'
import axios from "axios";
import { ElMessage } from 'element-plus'
// import storage from '@/utils/storage.js'
// 创建axios实例配置
const service = axios.create({
    baseURL: process.env.BASE_API,
    withCredentials: true, // 跨域安全策略 withCredentials: true, // 跨域安全策略
    timeout: 8000
})
/**
 * 请求拦截
 */
service.interceptors.request.use((req) => {
    const headers = req.headers
    const token = store.state.user.userinfo.token
    if (token) {
        if (!headers.Authorization) headers.Authorization = 'Bear ' + token
    }
    return req

})
/**
 * 响应拦截
 */
service.interceptors.response.use((res) => {
    const data = res?.data
    if (data?.code === 40001) {
        ElMessage.error(data?.msg)
    }
    return data
})
export default service